package com.atguigu.srb.core.controller.api;


import com.alibaba.fastjson.JSON;
import com.atguigu.common.result.Result;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.hfb.RequestHelper;
import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.service.LendService;
import com.atguigu.srb.core.service.UserAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author ZLHao
 * @since 2021-07-12
 */
@Api(tags = "标的")
@Slf4j
@RestController
@RequestMapping("/api/core/lend")
public class LendController {

    @Autowired
    private LendService lendService;

    @Autowired
    private UserAccountService userAccountService;

    @ApiOperation("投资列表")
    @GetMapping("/list")
    public Result list(){
        List<Lend> lends = lendService.selectAll();
        return Result.ok().data("lendList",lends);
    }
    @ApiOperation("标的详细信息")
    @GetMapping("/show/{id}")
    public Result show(@PathVariable Long  id ){

        Map<String, Object> lendDetail = lendService.selectById(id);
        return Result.ok().data("lendDetail",lendDetail);
    }

    @ApiOperation("计算投资收益")
    @GetMapping("/getInterestCount/{invest}/{yearRate}/{totalmonth}/{returnMethod}")
    public Result getInterestCount(
            @ApiParam(value = "投资金额", required = true)
            @PathVariable BigDecimal invest,
            @ApiParam(value = "年化收益", required = true)
            @PathVariable BigDecimal yearRate,
            @ApiParam(value = "期数", required = true)
            @PathVariable Integer  totalmonth,
            @ApiParam(value = "还款方式", required = true)
            @PathVariable Integer  returnMethod
                ){
        BigDecimal  interestCount = lendService.getInterestCount(invest,yearRate,totalmonth,returnMethod);
        return Result.ok().data("interestCount",interestCount);
    }



}

